<template>
	<view class="shop-declaration">
		<view class="box">
			<view>
				<input type="text" v-model="storeMsg.shopdesc" maxlength="14" placeholder="请填写名称(限制在14字哟)" />
			</view>
			<text>填写店铺宣言更能赢得用户的心哟</text>
			<view class="btn">
				<button type="primary" size="mini" @click="setShopDesc">确认</button>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex";
	export default {
		data() {
			return {
				value: '',
				storeMsg: {},
			}
		},
		computed: mapState(['shDetails']),
		onLoad() {
			// this.value = this.shDetails.shopdesc;
		},
		onShow() {
			this.storeMsg = uni.getStorageSync('lph-storeInfo');
		},
		methods: {
			...mapMutations(['changeShDetails']),
			async setShopDesc() {
				
				if (this.storeMsg.shopdesc.length < 4) {
					uni.showToast({
						title: '请至少输入4个字',
						icon: 'none'
					})
					return;
				}
				// this.changeShDetails(['shopdesc',this.value]); // vuex 保存店铺宣言
				let a = await this.$http.setShDesc({
					shopdesc: this.storeMsg.shopdesc
				});
				console.log(a);
				if (a.code == 200) {
					uni.setStorageSync('lph-storeInfo',this.storeMsg);
					uni.showToast({
						title: a.message,
						icon: 'none'
					});
					setTimeout(function() {
						uni.navigateBack()
					}, 500);
					return
				};
				uni.showToast({
					title: a.message,
					icon: 'none'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import 'static/css/myStore.scss';
</style>
